import Vue from 'vue'
import Vuex from 'vuex'
import Router from 'vue-router'
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading
Vue.use(Router)
Vue.use(Vuex)

import Layout from '../views/layout/Layout'
export const constantRouter = [
  { path: '/login', component: () => import('@/views/login'), hidden: true },
  { path: '/register', component: () => import('@/views/register'), hidden: true },
  { path: '/resetpassword', component: () => import('@/views/resetpassword'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'dashboard',
    hidden: true,
    meta: { title: '首页' },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页' }
    }]
  }
]
export const dataRouter = [
  {
    path: '/analyze',
    component: Layout,
    redirect: '/analyze/show',
    name: 'analyze',
    meta: { title: '数据分析', icon: 'example' },
    children: [
      {
        path: 'show',
        name: 'data',
        component: () => import('@/views/analyze/show'),
        meta: { title: '我的数据', icon: 'table' }
      },
      {
        path: 'show/:id',
        name: 'data',
        hidden: true,
        component: () => import('@/views/analyze/show'),
        meta: { title: '我的数据', icon: 'table' }
      },
      {
        path: 'history',
        name: 'history',
        component: () => import('@/views/analyze/list'),
        meta: { title: '历史数据', icon: 'table' }
      },
      {
        path: 'upload',
        name: 'upload',
        component: () => import('@/views/analyze/upload'),
        meta: { title: '上传csv', icon: 'table' }
      }
    ]
  }
]
export const userRouter = [

  {
    path: '/user',
    component: Layout,
    redirect: '/user/info',
    name: '用户中心',
    meta: { title: '用户中心', icon: 'example' },
    children: [
      {
        path: 'info',
        name: '用户信息',
        component: () => import('@/views/user/info'),
        meta: { title: '用户信息', icon: 'table' }
      }
    ]
  }
]
export const operatorRouter = [

  {
    path: '/user',
    component: Layout,
    redirect: '/user/info',
    name: '用户中心',
    meta: { title: '用户中心', icon: 'example' },
    children: [
      {
        path: 'info',
        name: '用户信息',
        component: () => import('@/views/user/info'),
        meta: { title: '用户信息', icon: 'table' }
      },
      {
        path: 'create',
        name: 'createAdmin',
        component: () => import('@/views/user/create'),
        meta: { title: '新建用户', icon: 'table' }
      },
      {
        path: 'list',
        name: '用户列表',
        component: () => import('@/views/user/list'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'applay/password',
        name: 'resetPassword',
        component: () => import('@/views/user/applypassword'),
        meta: { title: '重置密码', icon: 'table' }
      },
      {
        path: 'applay/num',
        name: 'numApply',
        component: () => import('@/views/user/applyNum'),
        meta: { title: '次数申请', icon: 'table' }
      }
    ]
  }
]
export const adminRouter = [

  {
    path: '/user',
    component: Layout,
    redirect: '/user/info',
    name: '用户中心',
    meta: { title: '用户中心', icon: 'example' },
    children: [
      {
        path: 'info',
        name: 'AdminInfo',
        component: () => import('@/views/user/info'),
        meta: { title: '用户信息', icon: 'table' }
      },
      {
        path: 'create',
        name: 'createAdmin',
        component: () => import('@/views/user/create'),
        meta: { title: '新建用户', icon: 'table' }
      },
      {
        path: 'list',
        name: '用户列表',
        component: () => import('@/views/user/list'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'applay/password',
        name: 'resetPassword',
        component: () => import('@/views/user/applypassword'),
        meta: { title: '重置密码', icon: 'table' }
      }
    ]
  }
]
/**
 * 普通用户的成功率查询
 */
export const conditionUserRouter = [
  {
    path: '/condition',
    component: Layout,
    redirect: '/condition/list',
    name: 'conditionQuery',
    meta: { title: '模拟借贷', icon: 'example' },
    children: [
      {
        path: 'product',
        name: 'product_list',
        component: () => import('@/views/product/list'),
        meta: { title: '借贷产品', icon: 'table' }
      },
      {
        path: 'apply',
        name: 'condition_create',
        component: () => import('@/views/condition/apply'),
        meta: { title: '自定义查询', icon: 'table' }
      },
      {
        path: 'list',
        name: 'condition_list',
        component: () => import('@/views/condition/list'),
        meta: { title: '我的查询', icon: 'table' }
      }
    ]
  },
  {
    path: '/post',
    component: Layout,
    redirect: '/post/list',
    name: 'post_list',
    meta: { title: '系统公告', icon: 'example' },
    children: [
      {
        path: 'list',
        name: 'post_list',
        hidden: true,
        component: () => import('@/views/post/list'),
        meta: { title: '查看公告', icon: 'table' }
      },
      {
        path: 'detail/:id',
        name: 'post_data',
        hidden: true,
        component: () => import('@/views/post/detail'),
        meta: { title: '公告详情', icon: 'table' }
      }
    ]
  },
  {
    path: '/lendng-product',
    component: Layout,
    redirect: '/lendng-product/list',
    name: 'product_list',
    hidden: true,
    meta: { title: '贷款产品', icon: 'example' },
    children: [
      {
        path: 'detail/:id',
        name: 'product_data',
        hidden: true,
        component: () => import('@/views/product/detail'),
        meta: { title: '产品详情', icon: 'table' }
      }
    ]
  }
]
/**
 * 管理员的成功率查询，可以审批申请
 */
export const conditionOperatorRouter = [
  {
    path: '/condition',
    component: Layout,
    redirect: '/condition/approve',
    name: 'condition_query_approve',
    meta: { title: '成功率查询审批', icon: 'example' },
    children: [
      {
        path: 'approve',
        name: 'condition_deal',
        component: () => import('@/views/condition/approve'),
        meta: { title: '处理查询申请', icon: 'table' }
      }
    ]
  },
  {
    path: '/post',
    component: Layout,
    redirect: '/post/list',
    name: 'post_list',
    meta: { title: '系统公告', icon: 'example' },
    children: [
      {
        path: 'list',
        name: 'post_list',
        component: () => import('@/views/post/list'),
        meta: { title: '查看公告', icon: 'table' }
      },
      {
        path: 'detail/:id',
        name: 'post_data',
        hidden: true,
        component: () => import('@/views/post/detail'),
        meta: { title: '公告详情', icon: 'table' }
      },
      {
        path: 'create',
        name: 'post_create',
        component: () => import('@/views/post/create'),
        meta: { title: '发布公告', icon: 'table' }
      },
      {
        path: 'approve',
        name: 'post_deal',
        component: () => import('@/views/post/approve'),
        meta: { title: '我的发布', icon: 'table' }
      }
    ]
  },
  {
    path: '/lendng-product',
    component: Layout,
    redirect: '/lendng-product/list',
    name: 'product_list',
    meta: { title: '贷款产品', icon: 'example' },
    children: [
      {
        path: 'list',
        name: 'product_list',
        component: () => import('@/views/product/list'),
        meta: { title: '查看全部', icon: 'table' }
      },
      {
        path: 'detail/:id',
        name: 'product_data',
        hidden: true,
        component: () => import('@/views/product/detail'),
        meta: { title: '产品详情', icon: 'table' }
      },
      {
        path: 'create',
        name: 'product_create',
        component: () => import('@/views/product/create'),
        meta: { title: '新增产品', icon: 'table' }
      },
     
      {
        path: 'history',
        name: 'product_myself',
        component: () => import('@/views/product/myproduct'),
        meta: { title: '管理产品', icon: 'table' }
      },
    ]
  }
]

export const deny = [
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  base: '/',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouter
  // routes: constantRouterMap2
})

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
